import 'package:flutter/material.dart';

class MyFlow extends StatefulWidget {
  ///列数
  final int line;

  ///需要布局的子组件
  final List<Widget> children;
  const MyFlow({Key key, this.children, this.line = 2}) : super(key: key);
  @override
  _MyFlowState createState() => _MyFlowState();
}

class _MyFlowState extends State<MyFlow> {
  @override
  Widget build(BuildContext context) {
    return Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: List(widget.line).asMap().keys.map((e) {
          return Expanded(
            flex: 1,
            child: Column(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: widget.children
                    .asMap()
                    .keys
                    .where((element) => element % widget.line == e)
                    .map((e) => widget.children[e])
                    .toList()),
          );
        }).toList());
  }
}
